package com.cyh.pangu.offer;

import java.util.LinkedHashMap;
import java.util.Map;

public class Offer50 {
    public char firstUniqChar(String s) {
        if (s == null) {
            return ' ';
        }
        char[] charArr = s.toCharArray();
        Map<Character, Boolean> map = new LinkedHashMap<>();
        for (char cc : charArr) {
            map.put(cc, map.containsKey(cc));
        }
        for (Map.Entry<Character, Boolean> entry : map.entrySet()) {
                if (!entry.getValue()) {
                    return entry.getKey();
                }
        }
        return ' ';
    }

    public char firstUniqChar_2(String s) {
        int[] count = new int[256];
        char[] chars = s.toCharArray();
        for (char ch : chars) {
                count[ch]++;
        }
        for (char ch : chars) {
            if (count[ch] == 1) {
                return ch;
            }
        }
        return ' ';
    }

    public static void main(String[] args) {
        Offer50 offer50 = new Offer50();
        char c = offer50.firstUniqChar("loveleetcode");
        System.out.println("c:" + c);
    }
}
